<% content_for :page_title do %>
  <%= Spree.t(:users) %>
<% end %>

<% content_for :page_actions do %>
  <%= button_link_to Spree.t(:new_user), new_admin_user_url, :class => "btn-success", :icon => 'add', :id => 'admin_new_user_link' %>
<% end %>

<% content_for :table_filter_title do %>
  <%= Spree.t(:search) %>
<% end %>

<% content_for :table_filter do %>
  <div data-hook="admin_users_index_search">
    <%= search_form_for [:admin, @search], url: spree.admin_users_url do |f| %>
      <div class="form-group">
        <%= f.label Spree.t(:email) %>
        <%= f.text_field :email_cont, class: "form-control js-quick-search-target" %>
      </div>
      <div class="row">
        <div class="col-md-6">
          <div class="form-group">
            <%= f.label Spree.t(:first_name) %>
            <%= f.text_field :bill_address_firstname_cont, :class => 'form-control' %>
          </div>
        </div>
        <div class="col-md-6">
          <div class="form-group">
            <%= f.label Spree.t(:last_name) %>
            <%= f.text_field :bill_address_lastname_cont, :class => 'form-control' %>
          </div>
        </div>
      </div>
      <div class="form-group">
        <%= f.label Spree.t(:company) %>
        <%= f.text_field :bill_address_company_cont, :class => 'form-control' %>
      </div>
      <div data-hook="admin_users_index_search_buttons" class="form-actions">
        <%= button Spree.t(:search), 'search' %>
      </div>
    <% end %>
  </div>
<% end %>

<table class="table" id="listing_users" data-hook>
  <thead>
    <tr data-hook="admin_users_index_headers">
      <th><%= sort_link @search,:email, Spree.t(:user), {}, {:title => 'users_email_title'} %></th>
      <th><%= Spree.t(:store_credits_total) %></th>
      <th><%= Spree.t(:store_credits_action) %></th>
      <th data-hook="admin_users_index_header_actions" class="actions"></th>
      <th data-hook="admin_users_index_header_actions" class="actions"></th>
    </tr>
  </thead>
  <tbody>
    <% @users.each do |user|%>
      <tr id="<%= spree_dom_id user %>" data-hook="admin_users_index_rows">
        <td class='user_email'><%=link_to user.email, edit_admin_user_url(user) %></td>
        <td><%= user.store_credits_total %></td>
        <td><%= link_to Spree.t(:credit), new_admin_user_credit_path(user_id: user) %> | <%= link_to Spree.t(:debit), new_admin_user_debit_path(user_id: user) %> | <%= link_to Spree.t(:view), admin_user_store_credits_path(user_id: user) %></td>

        <td data-hook="admin_users_index_row_actions" class="actions actions-2 text-right">
          <%= link_to_edit user, no_text: true %>
          <%= link_to_delete user, no_text: true %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<%= paginate @users %>
